package ru.dusniz.notifypeople.users;

import org.apache.tomcat.util.json.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;

@RestController("user")
@CrossOrigin(maxAge = 3600)
public class UserController {
    @Autowired
    UserService service;

    @GetMapping("/test")
    @ResponseBody
    public String test(@RequestParam(value = "test", required = false, defaultValue = "test") String test) {
        return "Test string: " + test;
    }

    @PostMapping("/register")
    @ResponseBody
    public boolean register(@RequestBody String data) throws ParseException {
        if (!service.saveUser(service.parseUserObj(data)))
//            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST);
            return false;
        else
            return true;
    }
}
